import { react, useState,useRef} from "react";
import store from '../store'
// 单向数据流
export default function Demo1(props) {
    const dom = useRef()

        let [data ,setData]  =  useState([])

    function addData(){
        store.dispatch({type: 'add' ,data:{
            name: 'zhangsan',
            age: 18
        }})
    }

    function getData(){
        const data = store.getState() 

        setData(data)

    
    }

    return (
        <div>
            <h1>Demo1</h1>
            <div  ref={dom}></div> 
            <button onClick={addData}>添加</button>
            <button onClick={getData}>获取</button> 


            <ul> 
                {
                    data.map((item,index) => {
                        return <li key={index}>{item.name}</li>
                    })
                }
            </ul>


  

        </div>
    )
}

